﻿using System;
using System.Web;
using System.Web.UI.WebControls;
using CxRomos.Core.Services;
using StructureMap;

namespace CxRomos.Web.App_Layouts {
    public partial class SiteMaster : System.Web.UI.MasterPage {
        private readonly INavigation _navigation = ObjectFactory.GetInstance<INavigation>();
        protected void Page_Load(object sender, EventArgs e) {
            _navigation.CheckAccessForCurrentNode();
        }

        protected void repPrimaryNav_ItemDataBound(object sender, RepeaterItemEventArgs e) {
            var linkPrimaryNav = e.Item.FindControl("linkPrimaryNav") as HyperLink;
            var node = (SiteMapNode) e.Item.DataItem;
            linkPrimaryNav.Text = node.Title;
            linkPrimaryNav.NavigateUrl = node.Url;
            if(node == _navigation.CurrentNode || node == _navigation.CurrentNode.ParentNode) {
                linkPrimaryNav.CssClass = "PrimaryNavLinkActive";
            }
        }

        protected void repFooter_ItemDataBound(object sender, RepeaterItemEventArgs e) {
            throw new NotImplementedException();
        }
    }
}
